package forces;

import java.awt.Dimension;
import java.util.List;

import simulation.Mass;
import util.Location;
import util.Vector;

/**
 * defines viscosity as an extension of Force.
 * @author Schwartz & Roy
 *
 */
public class Viscosity extends Force {

    //reasonable default value
    public static final double DEFAULT_VISCOSITY = 1.0;
    private double myViscosity;

    /**
     * constructor sets default viscosity to 1.0.
     */
    public Viscosity() {
        this(DEFAULT_VISCOSITY);
    }

    /**
     * constructor sets viscosity.
     * @param v is the specified viscosity
     */
    public Viscosity(double v) {
        super();
        myViscosity = v;
    }

    /**
     * @return the viscosity
     */
    public double getViscosity() {
        if (isOn()) {
            return myViscosity;
        }
        return 1.0;
    }

    /**
     * implements method because viscosity is a Force, but
     *      does nothing because viscosity is a scalar Force.
     */
    public Vector getForceVector(Location massLocation, Dimension bounds) {
        //viscosity does not return a vector
        return null;
    }

    /**
     * applies viscosity to Force in a scalar way.
     *      (different than other Forces' implementations)
     * @param masses is a list of all the masses in the simulation
     * @param bounds of the simulation
     */
    @Override
    public void applyForcesToMasses(List<Mass> masses, Dimension bounds) {
        for (Mass m : masses) {
            m.getAcceleration().scale(getViscosity());
        }
    }

}
